<template>
  <div class="change-wawa" id="change" v-bind:class="{nodata:list==null||list.length==0}">
    <div
      class="change-item"
      v-for="(i, key) in list"
      :key="key">
      <div class="order">
        <div class="top">
          <div class="name">兑换人：{{i.nickname}}</div>
          <div class="status">待处理</div>
        </div>
        <div class="goods">
          <img :src="i.pic_url" class="pic"/>
          <div class="info">
            <div class="goods-name">{{i.goods_name}}</div>
            <div class="price">
              <img src="../assets/goods_star.png" class="star"/>
              <div class="num">{{i.amount}}</div>
            </div>
          </div>
        </div>
        <div class="bottom">
          <div class="time">{{i.order_time}}</div>
          <div class="agree" @click="solveOrder(1,i.id)">同意</div>
          <div class="reject" @click="solveOrder(0,i.id)">拒绝</div>
        </div>
      </div>
    </div>

    <DialogWindow
      v-if="isDialogShow"
      :content="errmsg"
      showbtncode="1"
      :onCloseClick="onDialogCloseClick"/>
    <div class="no-content" v-if="list==null||list.length==0">
      <div class="no_img">
      <img src="../assets/no_data.png" class="img_nodata"/>
      </div>
      <div class="txt_nodata">当前还没有未处理订单哦</div>
    </div>
    <div class="check" @click="gotoSloveOrder">查看已经处理的订单></div>
  </div>
</template>

<script>
  import DialogWindow from '@/components/DialogWindow'
  import {getOrderList} from '@/api/api'
  import {handleOrders} from '@/api/api'
    export default {
      created(){
        let params={
          status:0,
          pagination: { // 分页参数 如果不传返回全部
            page: 1, // 当前页
            per_page: 10 // 每页条数 默认10
          },

        }
          getOrderList(params).then(res=>{
            if (res.code==0){
              this.list = res.data.data

            }
          })
      },
      data(){
        return{
          list:[

          ],
          isDialogShow:false,
          errmsg:null,
          pageNum:1,
          perPage:10,
          showlaoding: false,
          hasmore:true,
        }
      },
      components:{
        DialogWindow
      },
        name: "changewawa",
      methods:{
        getOrder(){
          console.log(this.pageNum)
          let params={
            status:0,
            pagination: { // 分页参数 如果不传返回全部
              page: this.pageNum, // 当前页
              per_page: 10 // 每页条数 默认10
            },

          }
          this.showlaoding=true
          getOrderList(params).then(res=>{
            if (res.code==0){
              if (this.pageNum == 1) {
                this.list = res.data.data
              }else{
                this.list = this.list.concat(res.data.data);
              }
              if (res.data.data.length > 0){
                this.hasmore=true
              }else {
                this.hasmore= false
              }

            }else{

            }
            this.showlaoding=false
          })
        },
        solveOrder(status,id){
          let params={
            check:status
          }

          handleOrders(id,params).then(res=>{
            if (res.code==0){
              this.getOrder()
            }else{
              this.isDialogShow=true
              this.errmsg=res.message
            }
          })

        },
        onDialogCloseClick () {
          this.isDialogShow=false;

        },
        gotoSloveOrder(){

            this.$router.push({path: '/sloveorder'});

        },
        scrollBottom() {


      //可滚动容器的高度
          let innerHeight = document.querySelector('#change').clientHeight;
//屏幕尺寸高度
          let outerHeight = document.documentElement.clientHeight;
//可滚动容器超出当前窗口显示范围的高度
          let scrollTop = document.documentElement.scrollTop;

          if (innerHeight < (outerHeight + scrollTop)||innerHeight == (outerHeight + scrollTop)) {
            //加载更多操作
            if (!this.showlaoding&&this.hasmore){
              this.pageNum++
              this.getOrder()
            }
          }
          // 滚动到页面底部时，请求前一天的文章内容

        }

      },
      mounted() {
        window.addEventListener('scroll', this.scrollBottom)

      },
    }
</script>

<style scoped>

  .change-wawa{
    width: 100%;
    height: auto;
    padding-top: 15px;
    background:rgba(239,239,244,1);
    padding-bottom: 47px;
  }
  .nodata{
    width: 100%;
    height: auto;
    padding-top: 15px;
    background: #fff;
    padding-bottom: 47px;
  }
  .change-item{
    width: 100%;
    height: auto;
  }
  .order{
    width: 95%;
    height:202px;
    background:rgba(255,255,255,1);
    border-radius:8px;
    margin: 0 auto;
    margin-bottom: 15px;

  }
  .top{
    width: 95%;
    height: 46px;
    margin: 0 auto;
  }
  .name{
    font-size:14px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(51,51,51,1);
    line-height:46px;
    float: left;
  }
  .status{
    font-size:14px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(57,176,253,1);
    line-height:46px;
    float: right;
  }
  .goods{
    width: 95%;
    height:114px;
    background:rgba(255,244,249,1);
    border-radius:16px;
    margin: 0 auto;
  }
  .pic{
    width: 90px;
    height: 90px;
    float: left;
    margin-top: 12px;
    margin-left: 12px;
    margin-right: 12px;
  }
  .info{
    max-width: 195px;
    height: auto;
    float: left;
  }
  .goods-name{
    font-size:16px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(51,51,51,1);
    line-height:22px;
    margin-top: 14px;
  }
  .price{
    width: auto;
    height: 24px;
    margin-top: 16px;

  }
  .star{
    width: 24px;
    height: 24px;
    margin-right: 8px;
    float: left;
  }
  .num{
    font-size:16px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(255,93,159,1);
    line-height:24px;
  }
  .bottom{
    width: 95%;
    height: 42px;
    margin: 0 auto;
  }
  .time{
    font-size:12px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(102,102,102,1);
    line-height:42px;
    float: left;
  }
  .agree{
    width:56px;
    height:22px;
    border-radius:13px;
    border:1px solid;
    font-size:12px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(102,102,102,1);
    line-height:22px;
    text-align: center;
    float: right;
    margin-left: 8px;
    margin-top: 10px;
  }
  .reject{
    width:56px;
    height:22px;
    border-radius:13px;
    border:1px solid;
    font-size:12px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(102,102,102,1);
    line-height:22px;
    text-align: center;
    float: right;
    margin-top: 10px;
  }
  .check{
    position: fixed;
    bottom: 0;
    width: 100%;
    height:47px;
    background:rgba(254,108,136,1);
    font-size:15px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(255,255,255,1);
    line-height:47px;
    text-align: center;
  }

  .no-content{
    position: absolute;
    width: 100%;
    height: 100%;
    background: #fff;
  }
  .img_nodata{
    width: 211px;
    height: 76px;
    margin: 0 auto;
    display: block;
    margin-top: 150px;
    text-align: center;
  }
  .txt_nodata{
    font-size:14px;
    font-family:PingFangSC-Light;
    font-weight:300;
    color:rgba(102,102,102,1);
    line-height:32px;
    margin-top: 14px;
    text-align: center;
    display: block;
    text-align: center;
  }
</style>
